package com.example.tourstor.myself;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.example.tourstor.R;

public class AboutActivity extends AppCompatActivity implements MyOneLineView.OnRootClickListener, MyOneLineView.OnArrowClickListener {

    String versionCode;
    String versionName;
    Toolbar about_toolbar;
    LinearLayout about_root;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);

        versionCode = APKVersionCodeUtils.getVersionCode(this) + "";
        versionName = APKVersionCodeUtils.getVerName(this);

        setToolBar();
        initView();
    }

    private void setToolBar() {
        about_toolbar = (Toolbar) findViewById(R.id.about_toolbar);

        about_toolbar.setTitle("关于");
        about_toolbar.setTitleTextColor(Color.WHITE);

        this.setSupportActionBar(about_toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);//左侧添加一个默认的返回图标
        getSupportActionBar().setHomeButtonEnabled(true);//设置返回键可用
        this.getSupportActionBar().setDisplayShowTitleEnabled(true);
    }

    //Toolbar的事件---返回
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == android.R.id.home){
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    public void initView(){

        about_root = (LinearLayout) findViewById(R.id.about_root);

        //使用示例，通过Java代码来创建MyOnelineView
        //icon + 文字 + 箭头
        about_root.addView(new MyOneLineView(this)
                .initNoIcon("版本号", versionName, true)
                /*.setDividerTopColor(R.color.head_bottom_color)*/
                .showDivider(true,true)
                .setDividerTopHigiht(250)
                .setOnRootClickListener(this, 1));

        //该版本特点
        about_root.addView(new MyOneLineView(this)
                .initNoIcon("版本说明", "", true)
                .setOnRootClickListener(this, 2));

        about_root.addView(new MyOneLineView(this)
                .initNoIcon("服务协议", "", true)
                .setOnRootClickListener(this, 3));


    }

    @Override
    public void onRootClick(View view) {

        switch ((int) view.getTag()) {
            case 1:
                Toast.makeText(this, "111", Toast.LENGTH_SHORT).show();
                break;
            case 2:
                Toast.makeText(this, "222", Toast.LENGTH_SHORT).show();
                break;
            case 3:
                Toast.makeText(this, "333", Toast.LENGTH_SHORT).show();
                break;
        }

    }

    @Override
    public void onArrowClick(View view) {

    }
}
